package net.pimpas.web.jsf.renderers.span.html;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;

import net.pimpas.web.jsf.components.UIComponentPimpasBase;
import net.pimpas.web.jsf.components.span.UISpan;
import net.pimpas.web.jsf.renderers.util.html.HtmlRendererBase;
import net.pimpas.web.jsf.util.ComponentUtils;

import org.apache.myfaces.shared_impl.renderkit.html.HTML;

public class HtmlSpanRenderer extends Renderer {

	@Override
	public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
		if(!component.isRendered()) return;
		if(!ComponentUtils.isCorrectComponentType(component, UISpan.class)) return;
		
		context.getResponseWriter().startElement(HTML.SPAN_ELEM, component);
		HtmlRendererBase.writeBaseHtmlAttributes(context, (UIComponentPimpasBase) component);
	}
	
	@Override
	public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
		if(!component.isRendered()) return;
		if(!ComponentUtils.isCorrectComponentType(component, UISpan.class)) return;
		
		// close span
		ResponseWriter writer = context.getResponseWriter();
		writer.endElement(HTML.SPAN_ELEM);
	}
}